package com.authine.cloudpivot.ext.model.order;

import com.authine.cloudpivot.ext.enums.order.OrderGoodsReturnsStatusEnum;
import com.authine.cloudpivot.ext.enums.order.OrderGoodsStatusEnum;
import com.authine.mvp.app.launcher.domain.SelectorFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @ClassName OrderGoodsReturnsDto
 * @Description: 订单商品退货表
 * @Author cjj
 * @Date 2021/4/9
 * @Version V1.0
 **/
@Data
@Schema(description = "OrderGoodsReturnsVO")
@ApiModel("订单商品退货表")
public class OrderGoodsReturnsVO {
    @Schema(description = "订单商品退货ID")
    private String id;
    @Schema(description = "客户订单ID")
    private String orderCustomerId;
    @Schema(description = "客户订单商品ID")
    private String orderCustomerGoodsId;
    @Schema(description = "供应商订单ID")
    private String orderVendorId;
    @Schema(description = "供应商订单商品ID")
    private String orderVendorGoodsId;
    @Schema(description = "客户退款金额")
    private BigDecimal customerAmount;
    @Schema(description = "供应商退款金额")
    private BigDecimal vendorAmount;
    @Schema(description = "数量")
    private BigDecimal quantity;

    @Schema(description = "退款商品原始状态")
    private OrderGoodsStatusEnum oldStatus;
    @Schema(description = "是否退平台")
    private Boolean isToPm;
    @Schema(description = "是否退货")
    private Boolean isReturns;
    @Schema(description = "开户行")
    private String bankInfo;
    @Schema(description = "银行账号")
    private String bankNo;
    @Schema(description = "联系电话")
    private String phone;
    @Schema(description = "退货联系地址")
    private String address;
    @Schema(description = "退货联系人")
    private String reveiver;
    @Schema(description = "退货联系号码")
    private String mobile;
    @Schema(description = "申请人ID")
    private SelectorFormat customerMemberId;
    @Schema(description = "申请人名称")
    private String customerMemberName;
    @Schema(description = "客户ID")
    private SelectorFormat customerOrganizationId;

    @Schema(description = "接收人ID")
    private SelectorFormat vendorMemberId;
    @Schema(description = "接受人名称")
    private String vendorMemberName;
    @Schema(description = "供应商ID")
    private SelectorFormat vendorOrganizationId;

    @Schema(description = "版本号")
    private Integer version;
    @Schema(description = "原退款单状态")
    private Integer originStatus;
    @Schema(description = "原退款商品原始状态")
    private Integer originOldStatus;
    @Schema(description = "当退款是转采时，财务需要确认是否收到供应商退款（true 已确认，false 待确认，null 不需要确认）")
    private Boolean transferRefundConfirm;
    @Schema(description = "退货商品状态")
    private OrderGoodsReturnsStatusEnum orderGoodsReturnsStatus;
    @Schema(description = "拓展字段")
    private String extendsAttr;
    @Schema(description = "客户订单状态")
    private String orderCustomerStatus;
    @Schema(description = "下单人名称")
    private String placeOrderFullname;
    @Schema(description = "客户组织名称")
    private String organizationName;
    @Schema(description = "erpPO")
    private String erpPO;
    @Schema(description = "品牌")
    private String brand;
    @Schema(description = "商品名称")
    private String name;
    @Schema(description = "型号")
    private String model;
    @Schema(description = "规格")
    private String spec;
    @Schema(description = "未税单价")
    private BigDecimal pretaxPrice;
    @Schema(description = "含税单价")
    private BigDecimal price;
    @Schema(description = "税率")
    private BigDecimal taxRate;
    @Schema(description = "单位")
    private String unit;
    @Schema(description = "交货(天)")
    private Integer delivery;
    @Schema(description = "退款数量")
    private BigDecimal refundQuantity;
    @Schema(description = "运费")
    private BigDecimal freight;
    @Schema(description = "商品合计")
    private BigDecimal pretaxTotal;
    @Schema(description = "总计")
    private BigDecimal pretaxAmount;
    @Schema(description = "可退数量")
    private BigDecimal quantityReturnable;
    @Schema(description = "银行账户名")
    private String bankAccount;

    @Schema(description = "退款说明")
    private String memo;

    @Schema(description = "客户名称")
    private String customerOrganizationName;
    @Schema(description = "供应商名称")
    private String vendorOrganizationName;

    //extends_attr: eg:{"logs":[{"operator":null,"operatorUserId":81,"behavior":"确认到货","memo":"","time":"2020-10-16 14:28:07"}]}

    public static OrderGoodsReturnsVO entityToVO(Map<String, Object> entity){

        OrderGoodsReturnsVO orderGoodsReturnsVO = new OrderGoodsReturnsVO();
        orderGoodsReturnsVO.setId(String.valueOf(entity.get("id")));
        orderGoodsReturnsVO.setOrderCustomerId(String.valueOf(entity.get("order_customer_id")));
        orderGoodsReturnsVO.setOrderCustomerGoodsId(String.valueOf(entity.get("order_customer_goods_id")));
        orderGoodsReturnsVO.setOrderVendorId(String.valueOf(entity.get("order_vendor_id")));
        orderGoodsReturnsVO.setOrderVendorGoodsId(String.valueOf(entity.get("order_vendor_goods_id")));
        //orderGoodsReturnsVO.setOldStatus(String.valueOf(entity.get("old_status")));
        orderGoodsReturnsVO.setCustomerAmount(new BigDecimal(String.valueOf(entity.get("customer_amount"))));
        orderGoodsReturnsVO.setVendorAmount(new BigDecimal(String.valueOf(entity.get("vendor_amount"))));
        orderGoodsReturnsVO.setIsToPm(Boolean.valueOf(String.valueOf(entity.get("is_to_pm"))));
        orderGoodsReturnsVO.setIsReturns(Boolean.valueOf(String.valueOf(entity.get("is_returns"))));
        orderGoodsReturnsVO.setMemo(String.valueOf(entity.get("memo")));
        orderGoodsReturnsVO.setBankInfo(String.valueOf(entity.get("bank_info")));
        orderGoodsReturnsVO.setBankNo(String.valueOf(entity.get("bank_no")));
        orderGoodsReturnsVO.setPhone(String.valueOf(entity.get("phone")));
        orderGoodsReturnsVO.setAddress(String.valueOf(entity.get("address")));
        orderGoodsReturnsVO.setReveiver(String.valueOf(entity.get("reveiver")));
        orderGoodsReturnsVO.setMobile(String.valueOf(entity.get("mobile")));
        orderGoodsReturnsVO.setCustomerMemberId((SelectorFormat) entity.get("customer_member_id"));
        orderGoodsReturnsVO.setCustomerMemberName(String.valueOf(entity.get("customer_member_name")));
        orderGoodsReturnsVO.setCustomerOrganizationId((SelectorFormat)entity.get("customer_organization_id"));
        orderGoodsReturnsVO.setCustomerOrganizationName(String.valueOf(entity.get("customer_organization_name")));
        orderGoodsReturnsVO.setVendorMemberId((SelectorFormat)entity.get("vendor_member_id"));
        orderGoodsReturnsVO.setVendorMemberName(String.valueOf(entity.get("vendor_member_name")));
        orderGoodsReturnsVO.setVendorOrganizationId((SelectorFormat)entity.get("vendor_organization_id"));
        orderGoodsReturnsVO.setVendorOrganizationName(String.valueOf(entity.get("vendor_organization_name")));
        orderGoodsReturnsVO.setVersion(Integer.valueOf(String.valueOf(entity.get("version"))));
        orderGoodsReturnsVO.setOriginStatus(Integer.valueOf(String.valueOf(entity.get("origin_status"))));
        orderGoodsReturnsVO.setOriginOldStatus(Integer.valueOf(String.valueOf(entity.get("origin_old_status"))));
        orderGoodsReturnsVO.setTransferRefundConfirm(Boolean.valueOf(String.valueOf(entity.get("transfer_refund_confirm"))));
       // orderGoodsReturnsVO.setOrderGoodsReturnsStatus(String.valueOf(entity.get("order_goods_returns_status")));
        orderGoodsReturnsVO.setExtendsAttr(String.valueOf(entity.get("extends_attr")));
        orderGoodsReturnsVO.setOrderCustomerStatus(String.valueOf(entity.get("order_customer_status")));
        orderGoodsReturnsVO.setPlaceOrderFullname(String.valueOf(entity.get("place_order_fullname")));
        orderGoodsReturnsVO.setOrganizationName(String.valueOf(entity.get("organization_name")));
        orderGoodsReturnsVO.setErpPO(String.valueOf(entity.get("erp_po")));
        orderGoodsReturnsVO.setBrand(String.valueOf(entity.get("brand")));
        orderGoodsReturnsVO.setName(String.valueOf(entity.get("name")));
        orderGoodsReturnsVO.setModel(String.valueOf(entity.get("model")));
        orderGoodsReturnsVO.setSpec(String.valueOf(entity.get("spec")));
        orderGoodsReturnsVO.setPretaxPrice(new BigDecimal(String.valueOf(entity.get("pretax_price"))));
        orderGoodsReturnsVO.setPrice(new BigDecimal(String.valueOf(entity.get("price"))));
        orderGoodsReturnsVO.setTaxRate(new BigDecimal(String.valueOf(entity.get("tax_rate"))));
        orderGoodsReturnsVO.setUnit(String.valueOf(entity.get("unit")));
        orderGoodsReturnsVO.setDelivery(Integer.valueOf(String.valueOf(entity.get("delivery"))));
        orderGoodsReturnsVO.setRefundQuantity(new BigDecimal(String.valueOf(entity.get("refund_quantity"))));
        orderGoodsReturnsVO.setFreight(new BigDecimal(String.valueOf(entity.get("freight"))));
        orderGoodsReturnsVO.setPretaxTotal(new BigDecimal(String.valueOf(entity.get("pretax_total"))));
        orderGoodsReturnsVO.setPretaxAmount(new BigDecimal(String.valueOf(entity.get("pretax_amount"))));
        orderGoodsReturnsVO.setRefundQuantity(new BigDecimal(String.valueOf(entity.get("quantity_returnable"))));
        orderGoodsReturnsVO.setBankAccount(String.valueOf(entity.get("bank_account")));

        return orderGoodsReturnsVO;
    }
}
